home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Evaluate / QueueStack.h < prev    next >
Text File  |  1991-05-17  |  3KB  |  88 lines

  1. /****************************************************************************************
  2. *
  3. *
  4. *            QueueStack.c    -Generic Stack and Queue Routines
  5. *
  6. *            ©1993, Graham Cox. Based on some work by Stephen Baxter, Ian Marshall et. al.
  7. *
  8. ****************************************************************************************/
  9.  
  10. #define        NIL            0L
  11.  
  12. #define        QueueType    0
  13. #define        StackType    1
  14.  
  15.  
  16. typedef struct
  17. {
  18.     struct    QSElem    **nextItem;        // Handle to next item in queue or stack
  19.     int                qElemType;        // Type of data this record holds
  20.     long            qData;            // the data. If < 4 bytes, this is the value, else address.
  21.     long            qFlags;            // reserved. Do not use.
  22. }
  23. QSElem, *QSElemPtr, **QSElemHdl;
  24.  
  25.  
  26. typedef struct
  27. {
  28.     int            StructType;            // Queue or Stack
  29.     QSElemHdl    QSHead;                // Handle to top of stack or last item in queue
  30.     QSElemHdl    QSTail;                // Handle to first item in queue, not used for stack
  31.     long        reserved;            // not used (yet!)
  32. }
  33. QSRec, *QSPtr, **QSHandle;
  34.  
  35.  
  36. /* data types that can be stacked or queued */
  37.  
  38. #define        QSInteger    0            //    LoWord of qData contains value
  39. #define        QSLong        1            //    qData contains data
  40. #define        QSFloat        2            //    qData contains handle of constant (float)
  41. #define        QSOperator    3            //    qData contains operator token in low 8 bits.
  42. #define        QSVariable    4            //    qData contains handle of variable (float + name)
  43. #define        QSString    5            //    qData contains handle of pascal string
  44. #define        QSTabVar    6            //    qData is index into variable table for this one
  45.  
  46. // other types may be added later- type codes > 6 are reserved.
  47.  
  48. /* function prototypes */
  49.  
  50. QSHandle    NewQSStruct(int sqType);        
  51.  
  52.                                     //    creates new queue or stack structure
  53.  
  54. void        DisposeQSStruct(QSHandle theQS);
  55.                                 
  56.                                     //    disposes struct and any data in it
  57.  
  58. QSElemHdl    NewQSItem(int qsType,long qsData);
  59.  
  60.                                     //    creates new element with data supplied
  61.                                 
  62. void        DisposeQSItem(QSElemHdl theItem);
  63.  
  64.                                     //  disposes of the item structure. If addresses are
  65.                                     //    referred to, you have to deal with that...
  66.                                 
  67. void        PushQSItem(QSElemHdl theItem,QSHandle theQS);
  68.  
  69.                                     // pushes item onto stack or queue
  70.                                 
  71. QSElemHdl    PopQSItem(QSHandle    theQS);
  72.  
  73.                                     // pops item from queue or stack. Note- depends on the
  74.                                     // type which item you get...
  75.                                 
  76. QSElemHdl    PeekQSItem(QSHandle    theQS);
  77.  
  78.                                     // as above but does not adjust structure
  79.                                 
  80. Boolean        EmptyQSStruct(QSHandle theQS);
  81.  
  82.                                     // returns TRUE if nothing in queue/stack, else FALSE
  83.                                 
  84. long        QSLength(QSHandle    theQS);
  85.                                 
  86.                                     // returns the number of items in the queue/stack.
  87.                                 
  88.